package com.example.common;

import com.alibaba.android.arouter.facade.annotation.Route;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

@Route(path = "/net/netlibxk")
public class NetlibXK  {

    private static NetlibXK netlibXK =null;
    public static NetlibXK getInstance(){
        if(netlibXK == null){
            synchronized (NetlibXK.class){
                if(netlibXK == null){
                    return netlibXK=new  NetlibXK();
                }
            }
        }
        return netlibXK;
    }

    Retrofit retrofit = null;
    public void   init(String baseurl){
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(new ReceivedCookiesInterceptor())
                .build();

         retrofit = new Retrofit.Builder()
                .baseUrl(baseurl)
                 .client(client)
                 .addConverterFactory(GsonConverterFactory.create())
                .build();

    }

    public   <T>T getService(Class<T> service){
        return retrofit.create(service);
    }



    public Retrofit getRetrofit() {
        return retrofit;
    }

    public void setRetrofit(Retrofit retrofit) {
        this.retrofit = retrofit;
    }



}
